﻿package export.magicWeapon
{
	import base.BaseBitmapDataClip;
	import base.BaseBitmapDataPool;
	import base.BaseHero;
	import base.BaseMagicWeapon;
	
	import com.game.data.vo.EquipmentVO;
	import com.greensock.TweenMax;
	
	import export.bullet.SpecialEffectBullet;
	
	import flash.geom.Point;
	
	public class MagicYuban extends BaseMagicWeapon
	{
		
		public function MagicYuban(param1:BaseHero)
		{
			super(param1);
		}
		
		override protected function initBBDC():void
		{
			var body:* = null;
			var bmdArray:Array = BaseBitmapDataPool.getBitmapDataArrayByName("MagicYubanBmd");
			if (bmdArray)
			{
				body = {
					"name"  : "body",
					"source": bmdArray
				};
				bbdc = new BaseBitmapDataClip([body], 59, 75, new Point(0, 0));
				bbdc.setOffsetXY(1, -10);
				bbdc.setFrameStopCount([[10], [9999]]);
				bbdc.setFrameCount([1, 1]);
				bbdc.setAddScriptWhenFrameOver(scriptFrameOverFunc);
				this.addChild(bbdc);
				return;
			}
			throw new Error("MagicBagua--BitmapData Error!");
		}
		
		override public function useSkill():void
		{
			var equip:EquipmentVO = this.sourceRole.getPlayer().getCurEquipByType("zbfb");
			if (equip)
			{
				super.useSkill();
			}
		}
		
		override public function showSkill():void
		{
			var bullet:* = undefined;
			var mon:* = undefined;
			var body:SpecialEffectBullet = null;
			var cd:int = 30;
			var equip:EquipmentVO = this.sourceRole.getPlayer().getCurEquipByType("zbfb");
			if (equip)
			{
				body = new SpecialEffectBullet("yubanEffect");
				body.x = this.sourceRole.x + 15;
				body.y = 420;
				body.setOwner(this.sourceRole);
				body.setDirect(0);
				body.setDisable();
				body.setIsDestroyWhenLastFrame(false);
				body.setDestroyInCount(gc.frameClips * 5);
				body.setFuncWhenEnterFrame(this.checkHit);
				body.setAction("hit1");
				gc.gameScene.addChild(body);
				this.sourceRole.magicBulletArray.push(body);
				if (equip.getFiveElementString().indexOf("木") != -1)
				{
					cd -= 5;
				}
				TweenMax.delayedCall(20, function (_self:MagicYuban):*
				{
					_self.setAction("idle");
				}, [this]);
			}
		}
		
		private function checkHit(param1:*):void
		{
			var _loc2_:int = 0;
			var multiply:int = this.sourceRole.getPlayer().getCurEquipByType("zbfb").getLevel() * 20;
			var bullet:* = undefined;
			var mon:* = undefined;
			var mons:Array = gc.pWorld.getMonsterArray();
			if (!param1)
			{
				return;
			}
			for each (mon in mons)
			{
				if (mon.magicBulletArray)
				{
					for each (bullet in mon.magicBulletArray)
					{
						if (bullet.sourceRole /* && !(bullet is SpecialEffectBullet) && !(bullet is FollowBaseObjectBullet)*/)
						{
							if (param1.getImgMc().hitTestObject(bullet.getImgMc()))
							{
								if (mon && !mon.isDead())
								{
									_loc2_ = Number(bullet.sourceRole.getRealPower(bullet.curAction)) * multiply;
									mon.reduceHp(_loc2_);
									trace("一路走好");
									param1.destroy();
								}
							}
						}
					}
				}
			}
		}
	}
}
